package cn.han.tickets;
//设计多线程编程模型，4个窗口共计售票100张
//本方案使用多线程编程方案1.继承Thread类的方式来完成
public class TestThread {
    public static void main(String[] args) {
        Ticket t4 = new Ticket();
        Ticket t1 = new Ticket();
        Ticket t2 = new Ticket();
        Ticket t3 = new Ticket();

        t4.start();
        t1.start();
        t2.start();
        t3.start();
    }
}
class Ticket extends Thread{
    static int tickets = 100;
    @Override
    public void run() {
//        super.run();
        while(true){
            try {
                //问题1：产生了重卖的现象
                //问题2：产生了超卖的现象

                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(getName()+"="+tickets--);
            if (tickets<=0)break;
        }
    }
}